import type { ProductCate, ProductCateDto, ProductCateTree } from '@/models/productCate'
import type { PageDto, CommonResult, CommonPage } from '@/models/request'
import request, { ContentTypeEnum } from '@/utils/request'
export function fetchList(parentId: number, params: PageDto) {
  return request<CommonPage<ProductCate>>({
    url: '/productCategory/list/' + parentId,
    method: 'get',
    params: params,
  })
}
export function deleteProductCate(id: number) {
  return request<CommonResult>({
    url: '/productCategory/delete/' + id,
    method: 'post',
  })
}

export function createProductCate(data: ProductCateDto) {
  return request<CommonResult>({
    url: '/productCategory/create',
    method: 'post',
    data: data,
  })
}

export function updateProductCate(data: ProductCateDto) {
  return request<CommonResult>({
    url: '/productCategory/update/' + data.id,
    method: 'post',
    data: data,
  })
}

export function getProductCate(id: number) {
  return request<CommonResult<ProductCate>>({
    url: '/productCategory/' + id,
    method: 'get',
  })
}

export function updateShowStatus(data: { ids: string; showStatus?: number }) {
  return request<CommonResult>({
    url: '/productCategory/update/showStatus',
    method: 'post',
    data: data,
    headers: { 'Content-Type': ContentTypeEnum.form },
  })
}

export function updateNavStatus(data: { ids: string; navStatus?: number }) {
  return request<CommonResult>({
    url: '/productCategory/update/navStatus',
    method: 'post',
    data: data,
    headers: { 'Content-Type': ContentTypeEnum.form },
  })
}

export function fetchListWithChildren() {
  return request<CommonResult<ProductCateTree[]>>({
    url: '/productCategory/list/withChildren',
    method: 'get',
  })
}
